package com.c611.smartclassroom.service.Impl;

import com.c611.smartclassroom.mapper.LogMapper;
import com.c611.smartclassroom.model.Log;
import com.c611.smartclassroom.model.LogExample;
import com.c611.smartclassroom.service.LogService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class LogServiceImpl implements LogService {

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    LogMapper logMapper;

    @Override
    public long queryLogCount() {
        LogExample logExample = new LogExample();
        logExample.createCriteria().andDelflagNotEqualTo(1);
        return logMapper.countByExample(logExample);
    }

    @Override
    public List<Log> queryLog(Integer page, Integer pageSize) {
        //增加分页
        RowBounds rowBounds = new RowBounds((page-1)*pageSize,pageSize);
        LogExample logExample = new LogExample();
        //增加排序
        logExample.setOrderByClause("operTime desc");

        //增加置废标识
        logExample.createCriteria().andDelflagNotEqualTo(1);
        return logMapper.selectByExampleWithRowbounds(logExample,rowBounds);
    }

    @Override
    public int addLog(Log log) {
        log.setOpertime(new Date());
        return logMapper.insertSelective(log);
    }

    @Override
    public List<Log> queryAllLog() {
        LogExample logExample = new LogExample();
        logExample.createCriteria().andDelflagNotEqualTo(1);
        return logMapper.selectByExample(logExample);
    }
}
